<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0  )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]

// 根据 HTTP_HOST 动态生成服务器 URL
define('API_SERVER_URL', ($_SERVER['HTTP_SCHEME'] ?? 'http' ) . '://' . ($_SERVER['HTTP_HOST'] ?? 'localhost'));

// 定义项目根目录 (根据您的实际项目结构可能需要调整)
// 通常，如果index.php在public目录下，那么项目根目录是public的上一级目录
define("ROOT_PATH", __DIR__ . "/../");

// Composer自动加载文件的路径
$vendorAutoload = ROOT_PATH . "vendor/autoload.php";

// 检查Composer依赖是否安装
if (!file_exists($vendorAutoload)) {
    // 依赖未安装，显示错误信息并终止脚本
    header("Content-Type: text/html; charset=utf-8");
    echo "<!DOCTYPE html>";
    echo "<html lang=\"zh-CN\"><body>";
    echo "<div style=\"text-align: center; margin-top: 50px; font-family: Arial, sans-serif;\">";
    echo "    <h1 style=\"color: #e44d26;\">项目依赖未安装！</h1>";
    echo "    <p style=\"font-size: 18px;\">请在项目根目录（通常是包含 `composer.json` 文件的目录）运行以下命令安装依赖：</p>";
    echo "    <pre style=\"background-color: #f4f4f4; padding: 15px; border-radius: 5px; display: inline-block;\"><code>composer install</code></pre>";
    echo "    <p style=\"font-size: 16px;\">如果您的系统尚未安装Composer，请访问 <a href=\"https://getcomposer.org/download/\" target=\"_blank\">getcomposer.org</a> 下载并安装 。</p>";
    echo "</div>";
    echo "<div style=\"text-align: center; color: #e44d26; margin-top: 50px; font-family: Arial, sans-serif;\">";
    echo "Raise Admin 温馨提醒</div>";
    echo "</body></html>";
    exit(1); // 终止脚本执行，避免后续错误
}

// 如果依赖已安装，则加载Composer自动加载文件
require $vendorAutoload;

use think\App;

// 执行HTTP应用并响应
$http = (new App( ))->http;

$response = $http->run( );

$response->send();

$http->end($response );
